import Mock from "mockjs";

let { data } = Mock.mock({
  // 20条数据
  "data|22": [
    {
      // 商品种类
      "goodsClass|1": ["运动鞋", "休闲鞋"],
      // 商品Id
      "goodsId|+1": 1,
      //商品名称
      "goodsName|1": [
        "乔丹Jordan",
        "耐克NIKE",
        "阿迪达斯Adidas",
        "AJ低帮藤原浩闪电",
        "DUNK SB黑白熊猫",
        "OW联名鞋",
      ],
      //商品售价
      "goodsSale|300-5000": 300,
      // 库存
      "goodsCount|100-5000": 100,
      // 销量
      "sale|500-9999": 500,
      // 状态
      "goodsState|1": ["销售中", "已下架", "未上架"],
      // 日期

      goodsDate: '@date("yyyy-MM-dd")',
      // 条码
      "goodsNum|1000000000000-9999999999999": 100000000000,
    },
  ],
});
interface ParamsType {
  page: number;
  size: number;
}
interface RemoveType {
  goodsId: number;
}

class ProductServe {
  getData({ page, size }: ParamsType) {
    return new Promise((resolve) => {
      const result = data.slice((page - 1) * size, page * size);
      resolve({
        status: 0,
        result: result,
        count: data.length,
      });
    });
  }

  removeData({ goodsId }: RemoveType) {
    return new Promise((resolve) => {
      data = data.filter((item: any) => item.goodsId !== goodsId);
      resolve({
        status: 0,
        result: data,
        msg: "删除成功",
      });
    });
  }
}

const puton = new ProductServe();
export default puton;
